package cn.kent.builderPattern;

import java.util.ArrayList;

/**
 * 定义一个车辆模型的抽象类，所有的车辆模型都继承这个类
 * @author kent
 * @date 2021/6/1 15:54
 */
public abstract class CarModel {

    // 这个参数是各个基本方法执行的顺序 -- 由客户提供
    private ArrayList<String> sequence = new ArrayList<>();


    /**
     * 模型启动开始跑了
     */
    protected abstract void start();
    protected abstract void stop();
    protected abstract void alarm();
    protected abstract void engineBoom();


    final public void run(){
        for (int i = 0; i < this.sequence.size(); i++) {
            String actionName = this.sequence.get(i);
            if (actionName.equalsIgnoreCase("start")){
                this.start();
            } else if (actionName.equalsIgnoreCase("stop")) {
                this.stop();
            } else if (actionName.equalsIgnoreCase("alarm")) {
                this.alarm();
            } else if (actionName.equalsIgnoreCase("engine boom")) {
                this.engineBoom();
            }
        }
    }

    final public void setSequence(ArrayList<String> sequence){
        this.sequence = sequence;
    }

}
